/**
 @Name：CLTPHP（Pro版） 管理员日志管理
 @Author：chichu
 @Site：http://www.cltphp.com/
 @License：CLTXY
 */
layui.define(['admin', 'table', 'util'], function (exports) {
    var $ = layui.$, admin = layui.admin, table = layui.table;
    //全部数据
    tableIn = table.render({
        elem: '#list',
        url: '/merch/merchMoneyLog/index',
        defaultToolbar:[],
        method: 'post',
        autoSort: false,
        page:true,
        cols: [[
            {field: 'id', title: '编号', width: 80, fixed: true,sort:true},
            {field: 'type_title', align: 'center', title: '类型', width: 200},
            {field: 'money', align: 'center', title: '余额变动', width: 100},
            {field: 'extra', align: 'center', title: '备注', width: 300},
            {field: 'source', align: 'center', title: '来源/去向', width: 150},
            {field: 'create_time', title: '操作时间',width: 180,sort:true}
        ]]
    });
    //监听排序事件
    table.on('sort(list)', function(obj){
        table.reload('list', {
            initSort: obj
            ,where: {sort_by: obj.field,sort_order: obj.type}
        });
    });



    var active = {
        reload: function () {
            var type = $('#type').val();
            var start_time = $('#start_time').val();
            var end_time = $('#end_time').val();
            //执行重载
            table.reload('list', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {type:type,start_time:start_time,end_time:end_time}
            });
        },
        export: function () {
            var type = $('#type').val();
            var start_time = $('#start_time').val();
            var end_time = $('#end_time').val();
            location.href='/merch/MerchMoneyLog/export?type='+type+'&start_time='+start_time+'&end_time='+end_time;
        }
    };
    $('.table-head-btn .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    exports('merchMoneyLog', {});
});